home *** CD-ROM | disk | FTP | other *** search
- 'Professor Mac's Coin Game
- 'By Dave Kelly
- ' ©MacTutor, DEC.1987
- ' For ZBasic™ version 4.0
-
- WINDOW OFF
- COORDINATE WINDOW
- DEF MOUSE=-1
- False=0:True=NOT False
- DIM Qrect%(3),Drect%(3),Nrect%(3),Prect%(3),Displayrect%(3)
- DIM 63 A$(4)
- Mousy=0:'Set up point record
- Mousx=0:'for mouse location
- WINDOW 1,"",(2,22)-(510,335),4
- CALL SETRECT(Qrect(0),388,0,510,80)
- CALL SETRECT(Drect(0),388,81,510,140)
- CALL SETRECT(Nrect(0),388,141,510,215)
- CALL SETRECT(Prect(0),388,216,510,310)
- CALL SETRECT(Displayrect(0),0,140,385,250)
- BUTTON 1,0,"Add Coins",(300,80)-(375,100),2
- BUTTON 2,0,"Subtract",(300,110)-(375,130),2
- APPLE MENU "About Professor Mac's Coins…"
- MENU 1,0,1,"File"
- MENU 1,1,1,"New Amount/N"
- MENU 1,2,1,"Quit/Q"
- EDIT MENU 2
- Amount!=0
- GOSUB "Get Coin Resources"
- GOSUB "Draw Page"
- ON MENU GOSUB "MenuEvent"
- ON DIALOG GOSUB "DialogEvent"
- ON MOUSE GOSUB "MouseEvent"
- MENU ON:DIALOG ON:MOUSE ON
- DO
- UNTIL TheEnd
- MENU OFF:DIALOG OFF:MOUSE OFF
- END
-
- "MenuEvent"
- Menunumber=MENU(0)
- Menuitem=MENU(1)
- MENU
- SELECT Menunumber
- CASE 255
- GOSUB "AppleMenu"
- GOSUB "Display Amount"
- GOSUB "Draw Page"
- CASE 1
- GOSUB "FileMenu"
- CASE 2
- END SELECT
- RETURN
-
- "AppleMenu"
- WINDOW 2,"",(100,40)-(415,310),-2
- TEXT 0,12
- PRINT @(5,1)"Professor Mac's Coin Game"
- PRINT @(10,2)"by"
- PRINT @(8,3)"Dave Kelly"
- PRINT @(7,4)"©MacTutor, 1987"
- PRINT @(7,5)"ZBasic version 4.0"
- PRINT @(3,8)"Professor Mac's MacTutor Store will"
- PRINT @(3,9)"display prices on the price tag."
- PRINT @(3,10)"The object is to select (by clicking)"
- PRINT @(3,11)"the fewest number of coins to equal"
- PRINT @(3,12)"the price. Hopefully this may be of"
- PRINT @(3,13)"assistance to children first learning"
- PRINT @(3,14)"about money."
- DO
- CALL GETMOUSE(Mousy)
- outsiderect=(Mousx<0 OR Mousx>300 OR Mousy<0 OR Mousy>270)
- UNTIL FN BUTTON AND NOT (outsiderect)
- WINDOW CLOSE 2
- RETURN
-
- "FileMenu"
- SELECT Menuitem
- CASE 1
- GOSUB "New"
- CASE 2
- GOSUB "Quit"
- END SELECT
- RETURN
-
- "Quit"
- 'Release all resource handles
- CALL RELEASERESOURCE(QHndl&)
- CALL RELEASERESOURCE(DHndl&)
- CALL RELEASERESOURCE(NHndl&)
- CALL RELEASERESOURCE(PHndl&)
- CALL RELEASERESOURCE(THndl&)
- CALL RELEASERESOURCE(MHndl&)
- END
-
- "New"
- RANDOMIZE TIMER
- Amount!=RND(100)*.01
- Add=True
- NumOfQ%=0
- NumOfD%=0
- NumOfN%=0
- NumOfP%=0
- Total!=0
- GOSUB "Display Amount"
- GOSUB "Display Total"
- GOSUB "Draw Display"
- BUTTON 1,2
- BUTTON 2,1
- RETURN
-
- "DialogEvent"
- Dilg=DIALOG(0)
- SELECT Dilg
- CASE 5
- RefWin=DIALOG(5):'Get window to refresh
- WINDOW 1
- GOSUB "Display Amount":GOSUB "Draw Page"
- CASE 1
- Buttonpressed=DIALOG(1)
- BUTTON Buttonpressed,2
- LONG IF Buttonpressed=1
- BUTTON 2,1
- Add=True
- XELSE
- BUTTON 1,1
- Add=False
- END IF
- END SELECT
- RETURN
-
- "Display Amount"
- TEXT 3,24,1,0
- PICTURE (60,50),THndl&
- CALL MOVETO (130,100)
- PRINT USING "$#.##";Amount!;SPC(2)
- RETURN
-
- "Display Total"
- TEXT 2,12,1,0
- CALL MOVETO(5,285)
- PRINT NumOfQ;" Quarters, ";NumOfD;" Dimes, ";NumOfN;" Nickels, ";NumOfP;" Pennies"
- CALL MOVETO(5,300)
- PRINT "Total:";USING "$#.##";Total!
- 'Check for winner
- IF Total!=Amount! AND Total!<>0 THEN GOSUB "WinDialog"
- RETURN
-
- "WinDialog"
- Temp!=Amount!
- CorrectNumOfQ%=Temp!/.25
- Temp!=Temp!-CorrectNumOfQ%*.25
- CorrectNumOfD%=Temp!/.1
- Temp!=Temp!-CorrectNumOfD%*.1
- CorrectNumOfN%=Temp!/.05
- Temp!=Temp!-CorrectNumOfN%*.05
- CorrectNumOfP%=Temp!*100
- LONG IF NumOfQ%=CorrectNumOfQ% AND NumOfD%=CorrectNumOfD% AND NumOfN%=CorrectNumOfN% AND NumOfP%=CorrectNumOfP%
- A$(1)="TA-DA! You Did it!"
- A$(2)="Select 'New Amount' to start again"
- A$(3)=""
- A$(4)=""
- CALL PARAMTEXT(A$(1),A$(2),A$(3),A$(4))
- Response%=FN ALERT(1,0)
- XELSE
- A$(1)="Nice Try!"
- A$(2)="You have too many coins!"
- A$(3)="You should have: "+STR$(CorrectNumOfQ%)+" Quarters, "+STR$(CorrectNumOfD%)+" Dimes,"
- A$(4)=STR$(CorrectNumOfN%)+" Nickels, "+STR$(CorrectNumOfP%)+" Pennies"
- CALL PARAMTEXT(A$(1),A$(2),A$(3),A$(4))
- Response%=FN ALERT(1,0)
- END IF
- Amount!=0
- BUTTON 1,0
- BUTTON 2,0
- RETURN
-
- "TooMuchDialog"
- A$(1)="Adding that coin will give you "+USING "$#.##";Total!
- A$(2)="Try a different coin!"
- A$(3)=" "
- A$(4)=" "
- CALL PARAMTEXT(A$(1),A$(2),A$(3),A$(4))
- Response%=FN ALERT(1,0)
- RETURN
-
- "No More Coins"
- A$(1)="Sorry, You don't have any more "+Coin$
- A$(2)=" "
- A$(3)=" "
- A$(4)=" "
- CALL PARAMTEXT(A$(1),A$(2),A$(3),A$(4))
- Response%=FN ALERT(1,0)
- RETURN
-
- "Get Coin Resources"
- QHndl&=FN GETNAMEDRESOURCE(CVI("PICT"),"Quarter")
- CALL LOADRESOURCE(QHndl&)
- DHndl&=FN GETNAMEDRESOURCE(CVI("PICT"),"Dime")
- CALL LOADRESOURCE(DHndl&)
- NHndl&=FN GETNAMEDRESOURCE(CVI("PICT"),"Nickel")
- CALL LOADRESOURCE(NHndl&)
- PHndl&=FN GETNAMEDRESOURCE(CVI("PICT"),"Penny")
- CALL LOADRESOURCE(PHndl&)
- THndl&=FN GETNAMEDRESOURCE(CVI("PICT"),"Tag")
- CALL LOADRESOURCE(THndl&)
- MHndl&=FN GETNAMEDRESOURCE(CVI("PICT"),"Professor Mac")
- CALL LOADRESOURCE(MHndl&)
- RETURN
-
- "Draw Page"
- PICTURE (400,0),QHndl&
- PICTURE (406,78),DHndl&
- PICTURE (400,138),NHndl&
- PICTURE (406,220),PHndl&
- CALL MOVETO(385,0)
- CALL PENSIZE(2,2)
- CALL LINETO(385,340)
- CALL MOVETO(0,135)
- CALL LINETO(385,135)
- CALL PENNORMAL
- PICTURE (0,0),MHndl&
- CALL MOVETO(60,40)
- TEXT 2,18,0,0
- PRINT "Professor Mac's Coin Game"
- "Draw Display"
- CALL ERASERECT(Displayrect(0))
- IF NumOfQ>0 THEN PICTURE (0,140),QHndl&
- IF NumOfD>0 THEN PICTURE (100,140),DHndl&
- IF NumOfN>0 THEN PICTURE (200,140),NHndl&
- IF NumOfP>0 THEN PICTURE (300,140),PHndl&
- RETURN
-
- "MouseEvent"
- IF Amount!=0 THEN FLUSHEVENTS:RETURN
- CALL GETMOUSE(Mousy)
- LONG IF (FN PTINRECT(Mousy,Qrect%(0)))
- LONG IF Add=True
- Total!=Total!+.25
- NumOfQ=NumOfQ+1
- GOSUB "Draw Display"
- XELSE
- LONG IF NumOfQ-1<0
- Coin$="Quarters!"
- GOSUB "No More Coins"
- XELSE
- NumOfQ=NumOfQ-1
- Total!=Total!-.25
- IF Total!<0 THEN Total!=Total!+.25
- GOSUB "Draw Display"
- END IF
- END IF
- LONG IF Total!>Amount!
- GOSUB "TooMuchDialog"
- Total!=Total!-.25
- NumOfQ=NumOfQ-1
- END IF
- GOSUB "Display Total"
- END IF
- LONG IF FN PTINRECT(Mousy,Drect(0))
- LONG IF Add=True
- Total!=Total!+.1
- NumOfD=NumOfD+1
- GOSUB "Draw Display"
- XELSE
- LONG IF NumOfD-1<0
- Coin$="Dimes!"
- GOSUB "No More Coins"
- XELSE
- NumOfD=NumOfD-1
- Total!=Total!-.1
- IF Total!<0 THEN Total!=Total!+.1
- GOSUB "Draw Display"
- END IF
- END IF
- LONG IF Total!>Amount!
- GOSUB "TooMuchDialog"
- Total!=Total!-.1
- NumOfD=NumOfD-1
- END IF
- GOSUB "Display Total"
- END IF
- LONG IF FN PTINRECT(Mousy,Nrect(0))
- LONG IF Add=True
- Total!=Total!+.05
- NumOfN=NumOfN+1
- GOSUB "Draw Display"
- XELSE
- LONG IF NumOfN-1<0
- Coin$="Nickels!"
- GOSUB "No More Coins"
- XELSE
- NumOfN=NumOfN-1
- Total!=Total!-.05
- IF Total!<0 THEN Total!=Total!+.05
- GOSUB "Draw Display"
- END IF
- END IF
- LONG IF Total!>Amount!
- GOSUB "TooMuchDialog"
- Total!=Total!-.05
- NumOfN=NumOfN-1
- END IF
- GOSUB "Display Total"
- END IF
- LONG IF FN PTINRECT(Mousy,Prect(0))
- LONG IF Add=True
- Total!=Total!+.01
- NumOfP=NumOfP+1
- GOSUB "Draw Display"
- XELSE
- LONG IF NumOfP-1<0
- Coin$="Pennies!"
- GOSUB "No More Coins"
- XELSE
- NumOfP=NumOfP-1
- Total!=Total!-.01
- IF Total!<0 THEN Total!=Total!+.01
- GOSUB "Draw Display"
- END IF
- END IF
- LONG IF Total!>Amount!
- GOSUB "TooMuchDialog"
- Total!=Total!-.01
- NumOfP=NumOfP-1
- END IF
- GOSUB "Display Total"
- END IF
- DO:UNTIL NOT (FN BUTTON)
- FLUSHEVENTS
- RETURN